package com.corecloud.tools;


import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间工具类
 */
public class DateUtils {


	/**
	 * 从当前时间获取指定天数之前时间
	 * @return
	 */
	public String getAgoDayByDayNum(Integer dayNum){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, - dayNum);
		Date d = c.getTime();
		return format.format(d);
	}


	/**
	 * 从当前时间获取向前一周时间数组
	 * @return
	 */
	public String[] getWeekDayByNow(){
		String[] weekDay = new String[7];
		SimpleDateFormat format = new SimpleDateFormat("MM-dd");
		Calendar c = Calendar.getInstance();
		for(int i = 0;i<7;i++){
			c.setTime(new Date());
			c.add(Calendar.DATE, - i);
			Date d = c.getTime();
			String ds = format.format(d);
			weekDay[i] = ds;
		}
		return weekDay;
	}



//	public static void main(String[] args) {
//		System.out.println(Arrays.toString(new DateUtils().getWeekDayByNow()));
//		System.out.println(new DateUtils().getAgoDayByDayNum(7));
//	}
}
